// 分析报告
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import CardC from '../../Barra/comps/cardC';
import style from './index.less';
import { TabC } from '@/src/components';
import LimitThroughC from '../../../reportingServices/limitThroughReportNew/limitThroughC';
import AssetAllocationC from '../../../PortfolioManagement/assetAllocation/AssetAllocationC';
import DayEndDeviationMonitoring from '../../../marketAnalysis/BondDeviationMonitoring/DayEndDeviationMonitoring';

@connect(({ loading }) => ({
  loading,
}))
export default class AnalysisReport extends PureComponent {
  constructor() {
    super();
    this.state = {
      activeKey: 'LimitRef',
      currentQuery: {}, // 持仓查询给的查询条件
    };
  }

  componentDidUpdate(prevProps) {
    if (this.props.reportArgs?.timeStamp != prevProps.reportArgs?.timeStamp) {
      // 活跃的tab更新
      const { activeKey } = this.state;
      if (activeKey != 'AssetRef') this[activeKey]?.settingAndSearch({ ...this.props.reportArgs });
      this.setState({
        currentQuery: { ...this.props.reportArgs },
      });
    }
  }

  // tab切换事件
  tabOnclick = (e) => {
    const { currentQuery } = this.state;
    this.setState(
      {
        activeKey: e,
      },
      () => {
        if (e != 'AssetRef') {
          if (this[e]) this[e]?.settingAndSearch({ ...currentQuery });
          else {
            // 初次加载的时候 有延时
            setTimeout(() => {
              this[e]?.settingAndSearch({ ...currentQuery });
            }, 200);
          }
        }
      },
    );
  };

  render() {
    const { activeKey } = this.state;
    return (
      <div style={{ height: '100%' }}>
        <div className={style.openBox} id='analysisReport'>
          {/* 展开 */}
          <CardC
            title='分析报告'
            type='34'
            showContent={true}
            titleIsShow={false}
            content={
              <div className={style.boxContent}>
                <TabC
                  type='secondTab'
                  tabSource={[
                    {
                      title: '限额监控',
                      key: 'LimitRef',
                      content: <LimitThroughC onRef={(e) => (this.LimitRef = e)} type='2' parentId='analysisReport' />,
                    },
                    {
                      title: '偏离监控',
                      key: 'MonitorRef',
                      content: <DayEndDeviationMonitoring pageType='2' parentId='analysisReport' onRef={(e) => (this.MonitorRef = e)} />,
                    },
                    {
                      title: '资产配置',
                      key: 'AssetRef',
                      content: <AssetAllocationC type='2' parentId='analysisReport' />,
                    },
                  ]}
                  activeKey={activeKey}
                  onChange={this.tabOnclick}
                />
              </div>
            }
          />
        </div>
        <div></div>
      </div>
    );
  }
}
